package com.lingz.manager.modules.wuxue.controller;

import com.lingz.manager.common.utils.ResultUtil;
import com.lingz.manager.common.vo.Result;
import com.lingz.manager.modules.wuxue.entity.DeviceInfo;
import com.lingz.manager.modules.wuxue.entity.dto.HistoryDataParam;
import com.lingz.manager.modules.wuxue.service.DataInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Classname DataInfoController
 * @Description 监测数据
 * @Date 2023/11/24 16:31
 * @Created by mjh
 */
@Slf4j
@RestController
@Api(description = "武穴设备监测数据管理接口")
@RequestMapping("/wuxue/monitorData")
@Transactional
public class DataInfoController {
    @Autowired
    DataInfoService dataInfoService;

    @GetMapping(value = "/requesthuangshiDataToDB")
    @ApiOperation(value = "请求huangshi数据保存到本地数据库")
    public Result<Object> requestHuangshiDataToDB(){
        dataInfoService.requestDataInfoToDB();
        return new ResultUtil<>().setData("同步成功！");
    }

    @GetMapping(value = "/requestYikemanDataToDB")
    @ApiOperation(value = "请求Yikeman数据保存到本地数据库")
    public Result<Object> requestYikemanDataToDB(){
        dataInfoService.requestYikemanDataToDB();
        return new ResultUtil<>().setData("同步成功！");
    }

    @GetMapping(value = "/requestTuopuDataToDB")
    @ApiOperation(value = "请求Tuopu数据保存到本地数据库")
    public Result<Object> requestTuopuInsectDataToDB(String start_date, String end_date){
        String res = dataInfoService.requestTuopuInsectDataToDB(start_date, end_date);
        return new ResultUtil<>().setData(res);
    }

    @GetMapping(value = "/requestWaterConservancyDataToDB")
    @ApiOperation(value = "请求水利设备监测数据保存到本地数据库")
    public Result<Object> requestWaterConservancyDataToDB(){
        dataInfoService.requestWaterConservancyDataToDB();
        return new ResultUtil<>().setData("同步成功");
    }


    @GetMapping(value = "/requestShanxunDataToDB")
    @ApiOperation(value = "请求Shanxun数据保存到本地数据库")
    public Result<Object> requestShanxunDataToDB(){
        dataInfoService.requestShanxunDataToDB();
        return new ResultUtil<>().setData("同步成功！");
    }

    @GetMapping("/getWeatherConditionByDeviceId")
    @ApiOperation("获取气象设备id来获取最近的天气情况")
    public Result<Object> getWeatherConditionByDeviceId(String deviceId){
        return new ResultUtil<>().setData(dataInfoService.getWeatherConditionByDeviceId(deviceId));
    }

    @GetMapping("/getHistoryData")
    @ApiOperation("获取气象设备id和对应的字段来获取历史数据记录")
    public Result<Object> getHistoryData(HistoryDataParam historyDataParam){
        return new ResultUtil<>().setData(dataInfoService.getHistoryData(historyDataParam));
    }
}
